import javafx.geometry.VPos;
import org.junit.Test;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class Solution202 {
    /**
     * 快乐数
     */
    public boolean isHappy(int n) {
        Set<Integer> set = new HashSet<>();
        while (true) {
            if (n == 1) return true;
            if (set.contains(n)) return false;
            set.add(n);
            int tmp = 0;
            while (n != 0) {
                tmp += Math.pow(n % 10, 2);
                n /= 10;
            }
            n = tmp;
        }
    }

    @Test
    public void test() {
        isHappy(19);
    }
}
